using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Net;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Dzzzr;

namespace MonitoringServer
{
  /// <summary>
  /// Page with google maps control
  /// </summary>
  public partial class Google : System.Web.UI.Page
  {
    /// <summary>
    /// Set up page for AJAX using 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
      //scriptManager.RegisterAsyncPostBackControl(ddlGames);
      if (!IsPostBack)
      {
        ddlDelay.SelectedValue = "10000";
        RefreshGameList();
        if (!String.IsNullOrEmpty(ddlGames.SelectedValue))
          RefreshMarkerList(Convert.ToInt32(ddlGames.SelectedValue));

      }

      //if (!String.IsNullOrEmpty(ddlGames.SelectedValue))
      //  RefreshMarkerList(Convert.ToInt32(ddlGames.SelectedValue));

      //Fill hidden controls with Login and password (for AJAX purposes)
      //hidLogin.Value = GetLogin();
      //hidPassword.Value = GetPassword();
      
      //Set web service reference 
      //ServiceReference reference = new ServiceReference();
      //reference.InlineScript = false;
      //scriptManager.Services.Add(reference);
    }

    private void RefreshGameList()
    {
      //MonitoringClient monitoringClient = new MonitoringClient();
      //Game[] games = monitoringClient.GetGameList(Helper.UserName, Helper.Password);
      List<Game> games = Game.GetGameList(0);
      ddlGames.DataSource = games;
      //ddlGames.DataMember = "ID";
      ddlGames.DataValueField = "ID";
      ddlGames.DataTextField = "Name";
      ddlGames.DataBind();
    }

    private void RefreshMarkerList(int gameID)
    {
      //AJAXService service = new AJAXService();
      List<Entity> entities = Entity.GetGameEntityList(gameID);
      lbMarkers.DataSource = entities;
      lbMarkers.DataValueField = "ID";
      lbMarkers.DataTextField = "Name";
      lbMarkers.DataBind();
    }

    protected void ddlGames_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (!String.IsNullOrEmpty(ddlGames.SelectedValue))
        RefreshMarkerList(Convert.ToInt32(ddlGames.SelectedValue));
    }
  }
}
